package cn.wilson.hrm.web.controller;

import cn.wilson.hrm.dto.SendSmsDTO;
import cn.wilson.hrm.service.IVerifyCodeService;
import cn.wilson.hrm.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;


    /**
     *      获取图片验证码的api
     * @param imageKey
     * @return
     */
    @GetMapping("/verifycode/imageCode/{imageKey}")
    public AjaxResult createImageCode(@PathVariable("imageKey") String imageKey){
        String base64ImageStr = verifyCodeService.createImageCode(imageKey);

        return AjaxResult.me().setResultObj(base64ImageStr);
    }



    @PostMapping("/verifycode/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody SendSmsDTO sendSmsDTO){
        try {
            verifyCodeService.sendSmsCode(sendSmsDTO);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }

    }


}
